//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System;
using System.Collections.Generic;

namespace WCSFContrib.PageFlow
{
	/// <summary>
	/// Describes an instance of a Page that can be used as in a PageFlow
	/// </summary>
	public class Page
	{
		private string _name;
		private string _url;
		private string _defaultTransition;
		private List<string> _transitions;

		/// <summary>
		/// Creates an instance of a <see cref="Page"/> with the given name and URL.
		/// </summary>
		/// <param name="name">The name of the page.</param>
		/// <param name="url">The URL of the page.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#")]
        public Page(string name, string url)
		{
			_name = name;
			_url = url;
		}

		/// <summary>
		/// Creates an instance of a <see cref="Page"/> with the given properties.
		/// </summary>
		/// <param name="name">The name of the page.</param>
		/// <param name="url">The URL of the page.</param>
		/// <param name="defaultTransition">The default transition to use when navigating from the page.</param>
		/// <param name="transitions">An enumeration of possible transitions from the page.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#")]
        public Page(string name, string url, string defaultTransition, IEnumerable<string> transitions)
            : this(name, url)
		{
			_defaultTransition = defaultTransition;
			_transitions = new List<string>(transitions);
		}

		/// <summary>
		/// Gets the name of the page.
		/// </summary>
		public string Name
		{
			get { return _name; }
		}

		/// <summary>
		/// Gets the URL.
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
        public string Url
		{
            get { return _url; }
		}

		/// <summary>
		/// Gets the default transition.
		/// </summary>
		public string DefaultTransition
		{
			get { return _defaultTransition; }
		}

		/// <summary>
		/// Gets a collection of possible transitions.
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public TransitionCollection Transitions
		{
			get { return new TransitionCollection(_transitions); }
		}

		/// <summary>
		/// Serves as a hash function for a particular type.
		/// </summary>
		/// <returns>A hash code for the current Object.</returns>
		public override int GetHashCode()
		{
			return _name.GetHashCode();
		}

		/// <summary>
		/// Determines whether the specified Object is equal to the current Page. 
		/// </summary>
		/// <param name="obj">The Object to compare with the current Page.</param>
		/// <returns>true if the specified Object is equal to the current Page; otherwise, false.</returns>
		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			else if (!(obj is Page))
			{
				return false;
			}
			else
			{
				return obj.GetHashCode() == GetHashCode();
			}
		}
	}
}
